//////////////////////////////////////////////////////////////////////////////////////////////////
//
//	File: kernel.h
//
//	Original author: Tomas Sandnes / NITH / 2009
//	Changed by:	---
//
//	Description: Out main heart of the whole thing - the "game loop"! :-)
//
//	Special notes: ---
//
//////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef KERNEL_H  // Inclusion guard.
#define KERNEL_H



// I N C L U D E S
// ===============

#include "GCPtr.h"
#include "kernelTask.h"
#include "UpdateTimer.h"
#include "Input.h"
#include "Renderer2d.h"
#include "Net_Client.h"

typedef std::list< GCPtr<IKernelTask> > taskList;

// C L A S S   D E C L A R A T I O N
// =================================

class CKernel
{
public:
	CKernel();
	virtual ~CKernel();

	// The "heart-pump", looping over and over as long as there are tasks left 
	// in the active-list, running their Update() functions. (Unless the tasks 
	// are flagged for removal/kill: In that case their Stop() functions are 
	// run instead, and they are removed from the list.)
	int Execute();

	// Killing all tasks (which includes running their Stop() functions), 
	// on next update-loop in Execute.
	void RemoveAllTasks();

	// Adding a task to the active-list and running it's Start().
	bool AddTask(GCPtr<IKernelTask> &pgTask);

	// Flagging a task for removal (kill), which will happen on next update. 
	// (And it's Stop() function will be run at that time too.)
	void RemoveTask(GCPtr<IKernelTask> &pgTask);

	// Pausing task. (Moving it to the pause-list, running it's Suspend().)
	void SuspendTask(GCPtr<IKernelTask> &pgTask);

	// Unpausing task. (Moving it to the active-list, running it's Resume().)
	void ResumeTask(GCPtr<IKernelTask> &pgTask);

protected:
	//CLog m_oLog;

	taskList m_oTaskList;		// Currently active tasks.
	taskList m_oPausedTaskList;  // Paused tasks.

};



#endif  // END Inclusion guard.